/*
 * ComputeNonablationHeatfluxMaterial.C
 *
 *  Created on: Feb 4, 2020
 *      Author: liuxiao
 */



#include<iostream>

#include "../../include/materials/ComputeNonablationHeatfluxMaterial.h"
#include "libmesh/quadrature.h"
#include "libmesh/system.h"
#include "libmesh/radial_basis_interpolation.h"
using std::cout;
using std::endl;
registerMooseObject("TrilobitaApp", ComputeNonablationHeatfluxMaterial);
template<>
InputParameters validParams<ComputeNonablationHeatfluxMaterial>()
{
	InputParameters params = validParams<Material>();
	params.addRequiredCoupledVar("temperature_varialble", "Coupled wall temperature");
	return params;
}


ComputeNonablationHeatfluxMaterial::ComputeNonablationHeatfluxMaterial(const InputParameters & parameters) :
    	    										Material(parameters),
	_hw(declareProperty<Real>("wall_enthalpy")),
	_qh(declareProperty<Real>("hotwall_heatflux")),
	_qrad_out(declareProperty<Real>("heatflux_rad_out")),
	_qn(declareProperty<Real>("net_heatflux")),
	_qc(getMaterialProperty<Real>("coldwall_heatflux")),
	_hr(getMaterialProperty<Real>("recovery_enthalpy")),
	_Tw_qc(getMaterialProperty<Real>("Tw_for_coldwall_heatflux")),
	_epsilon(getMaterialProperty<Real>("surface_emissivity")),
	_temperature(coupledValue("temperature_varialble")),
	_sigma(5.67e-08)

{

}



Real ComputeNonablationHeatfluxMaterial::compute_hw(Real Tw)
{
	return 1000*Tw;
}


void ComputeNonablationHeatfluxMaterial::computeProperties()
{

	for (unsigned int qp(0);qp < _qrule->n_points(); ++qp)
	{
		_hw[qp]=compute_hw(_temperature[qp]);
		if(abs(_hr[qp]-_hw[qp])<=1)
		{
			_qh[qp]=0;
		}
		else
		{
			_qh[qp]=_qc[qp]*(_hr[qp]-_hw[qp])/(_hr[qp]-compute_hw(_Tw_qc[qp]));
		}
		_qrad_out[qp]=_epsilon[qp]*_sigma*pow(_temperature[qp],4);
		_qn[qp]=_qh[qp]-_qrad_out[qp];
	}

}







